package cn.tedu.egnotiec1.controller;

import cn.tedu.egnotiec1.mapper.NoticeMapper;
import cn.tedu.egnotiec1.pojo.dto.NoticeAddParam;
import cn.tedu.egnotiec1.pojo.dto.NoticeListQuery;
import cn.tedu.egnotiec1.pojo.entity.Notice;
import cn.tedu.egnotiec1.pojo.vo.NoticeListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class NoticeController {
    private NoticeMapper noticeMapper;

    @PostMapping("/v1/notice/add")
    @ResponseBody
    public String insertNotice(NoticeAddParam noticeAddParam){
        System.out.println("添加咨询" + noticeAddParam);
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam, notice);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        notice.setUserId(1L);
        noticeMapper.insertNotice(notice);
        return "新增咨询成功";
    }

    @GetMapping("/v1/notice/list")
    @ResponseBody
    public List<NoticeListVO> listNotice(NoticeListQuery noticeListQuery){
        System.out.println("查询咨询列表" + noticeListQuery);
        List<NoticeListVO> list = noticeMapper.selectListNotiect(noticeListQuery);
        return list;
    }


}
